package com.ruoyi.web.controller.base;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.base.domain.BasPollutionsource;
import com.ruoyi.base.domain.BasePipenetworkassociationtable;
import com.ruoyi.base.domain.BusWaterSegment;
import com.ruoyi.base.service.IBusWaterSegmentService;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.base.domain.BusWaterSegmentorrhoutfall;
import com.ruoyi.base.service.IBusWaterSegmentorrhoutfallService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 断面和入河排口关联关系 （在用）Controller
 * 
 * @author maliang
 * @date 2025-07-27
 */
@RestController
@RequestMapping("/base/segmentorrhoutfall")
public class BusWaterSegmentorrhoutfallController extends BaseController
{
    @Autowired
    private IBusWaterSegmentorrhoutfallService busWaterSegmentorrhoutfallService;
    @Autowired
    private IBusWaterSegmentService busWaterSegmentService;

    /**
     * 查询断面和入河排口关联关系 （在用）列表
     */
    //@PreAuthorize("@ss.hasPermi('base:segmentorrhoutfall:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusWaterSegmentorrhoutfall busWaterSegmentorrhoutfall)
    {
        startPage();
        List<BusWaterSegmentorrhoutfall> list = busWaterSegmentorrhoutfallService.selectBusWaterSegmentorrhoutfallList(busWaterSegmentorrhoutfall);
        return getDataTable(list);
    }

    /**
     * 导出断面和入河排口关联关系 （在用）列表
     */
    //@PreAuthorize("@ss.hasPermi('base:segmentorrhoutfall:export')")
    @Log(title = "断面和入河排口关联关系 （在用）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusWaterSegmentorrhoutfall busWaterSegmentorrhoutfall)
    {
        List<BusWaterSegmentorrhoutfall> list = busWaterSegmentorrhoutfallService.selectBusWaterSegmentorrhoutfallList(busWaterSegmentorrhoutfall);
        ExcelUtil<BusWaterSegmentorrhoutfall> util = new ExcelUtil<BusWaterSegmentorrhoutfall>(BusWaterSegmentorrhoutfall.class);
        util.exportExcel(response, list, "断面和入河排口关联关系 （在用）数据");
    }

    /**
     * 获取断面和入河排口关联关系 （在用）详细信息
     */
    //@PreAuthorize("@ss.hasPermi('base:segmentorrhoutfall:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(busWaterSegmentorrhoutfallService.selectBusWaterSegmentorrhoutfallById(id));
    }

    /**
     * 新增断面和入河排口关联关系 （在用）
     */
    //@PreAuthorize("@ss.hasPermi('base:segmentorrhoutfall:add')")
    @Log(title = "断面和入河排口关联关系 （在用）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusWaterSegmentorrhoutfall busWaterSegmentorrhoutfall)
    {
        return toAjax(busWaterSegmentorrhoutfallService.insertBusWaterSegmentorrhoutfall(busWaterSegmentorrhoutfall));
    }

    @GetMapping("/segment/{rhoutfallId}")
    public AjaxResult segmentbypwdid(@PathVariable("rhoutfallId") String rhoutfallid){
        List<BusWaterSegment> busWaterSegmentList = new ArrayList<>();
        BusWaterSegmentorrhoutfall busWaterSegmentorrhoutfallParam = new BusWaterSegmentorrhoutfall();
        busWaterSegmentorrhoutfallParam.setRhoutfallid(rhoutfallid);
        List<BusWaterSegmentorrhoutfall> busWaterSegmentorrhoutfallList = busWaterSegmentorrhoutfallService.selectBusWaterSegmentorrhoutfallList(busWaterSegmentorrhoutfallParam);
        if(!CollectionUtils.isEmpty(busWaterSegmentorrhoutfallList)){
            for (BusWaterSegmentorrhoutfall busWaterSegmentorrhoutfall : busWaterSegmentorrhoutfallList) {
                if(StringUtils.isNotEmpty(busWaterSegmentorrhoutfall.getSegmentid())){
                    BusWaterSegment busWaterSegment = busWaterSegmentService.selectBusWaterSegmentByID(busWaterSegmentorrhoutfall.getSegmentid());
                    if(busWaterSegment != null){
                        busWaterSegmentList.add(busWaterSegment);
                    }
                }
            }
        }
        return AjaxResult.success(busWaterSegmentList);
    }

    /**
     * 修改断面和入河排口关联关系 （在用）
     */
    //@PreAuthorize("@ss.hasPermi('base:segmentorrhoutfall:edit')")
    @Log(title = "断面和入河排口关联关系 （在用）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusWaterSegmentorrhoutfall busWaterSegmentorrhoutfall)
    {
        return toAjax(busWaterSegmentorrhoutfallService.updateBusWaterSegmentorrhoutfall(busWaterSegmentorrhoutfall));
    }

    /**
     * 删除断面和入河排口关联关系 （在用）
     */
    //@PreAuthorize("@ss.hasPermi('base:segmentorrhoutfall:remove')")
    @Log(title = "断面和入河排口关联关系 （在用）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(busWaterSegmentorrhoutfallService.deleteBusWaterSegmentorrhoutfallByIds(ids));
    }
}
